package com.imooc.api;

import com.imooc.bilibili.domain.JsonResponse;
import com.imooc.bilibili.service.FileService;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * ProjectName imooc-bilibili
 *
 * @author xieyucan
 * <br>CreateDate 2022/10/26 9:14
 */
@RestController
public class FileApi {

    @Resource
    private FileService fileService;

    @PostMapping("/md5files")
    public JsonResponse<String> getMd5File(MultipartFile file) throws IOException {
        String fileMd5=fileService.getMd5File(file);
        return new JsonResponse<>(fileMd5);
    }

    @PutMapping("/file-slices")
    public JsonResponse<String> uploadSliceFile(MultipartFile file,String fileMd5,Integer sliceNo,Integer totalSliceNo) throws IOException {
        String filePath=fileService.uploadSliceFile(file,fileMd5,sliceNo,totalSliceNo);
        return new JsonResponse<>(fileMd5);
    }
}
